﻿using System;
using System.Linq;
using BlogML.Xml;
using NGM.BlogML.Models;
using Orchard.ContentManagement;

namespace NGM.BlogML.Services.Stratagies {
    public class AuthorsImportStratagy : IMultipleImportStratagy {
        private readonly IUserServices _userService;

        public AuthorsImportStratagy(IUserServices userService) {
            _userService = userService;
        }

        public bool IsType(object objectToImport) {
            return objectToImport is BlogMLPost.AuthorReferenceCollection;
        }

        public ContentItem Import(ImportSettings importSettings, BlogMLBlog blog, object objectToImport, IContent parentContent) {
            var authorsToImport = (BlogMLPost.AuthorReferenceCollection)objectToImport;

            if (authorsToImport.Count == 0)
                return null;

            var authors = authorsToImport.Cast<BlogMLAuthorReference>()
                .Select(t => blog.Authors.First(c => c.ID == t.Ref));

            foreach (var author in authors) {
                var user = _userService.GetUser(author.Title, author.Email, true);    
            }

            return null;
        }

        public void ImportAdditionalContentItems<T>(ImportSettings importSettings, BlogMLBlog blog, T objectToImport, IContent parentContent) {
            throw new NotSupportedException();
        }
    }
}